/*
 * @Description: 
 * @Author: changqing
 * @Date: 2021-08-17 16:50:50
 * @LastEditTime: 2021-08-17 16:55:12
 * @LastEditors: changqing
 * @Usage: 
 */

// 多播返回一个 Observable，它看起来像一个普通的 Observable，
// 但在订阅时就像一个 Subject。多播返回一个 ConnectableObservable，它只是一个带有 connect() 方法的 Observable。
var { from, Subject } =  require('rxjs');
var { multicast } = require('rxjs/operators');

const source = from([1, 2, 3]);
const subject = new Subject();
const multicasted = source.pipe(multicast(subject));

// These are, under the hood, `subject.subscribe({...})`:
multicasted.subscribe({
  next: (v) => console.log(`observerA: ${v}`)
});
multicasted.subscribe({
  next: (v) => console.log(`observerB: ${v}`)
});

// This is, under the hood, `source.subscribe(subject)`:
multicasted.connect();